/************************************************************************
 * @file ConsoleLogCommand.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <iostream>

#include <QDateTime>
#include <QObject>
#include <QThread>

#include <plugin/command/ConsoleLogCommand.h>

using namespace std;

namespace antu
{
namespace plugin
{
ConsoleLogCommand::ConsoleLogCommand()
{
}

void ConsoleLogCommand::init()
{
}

void ConsoleLogCommand::debug(const QString &fileName, int line, const QString &className, const QString &methodName, const QString &message)
{
	if (this->m_eLogType > LoggerService::LVL_DEBUG)
		return;

    QString content = QObject::tr("%1 [%2] ") + fileName + " line:%3 -- %4::%5 -- %6";
    content = content.arg(QDateTime::currentDateTime().toString()).arg(QThread::currentThread()->objectName()).arg(line).arg(className).arg(methodName).arg(message);

    qDebug(qPrintable(content));
}

void ConsoleLogCommand::info(const QString &fileName, int line, const QString &className, const QString &methodName, const QString &message)
{
	if (this->m_eLogType > LoggerService::LVL_INFO)
		return;

	QString content = QObject::tr("%1 [%2] ") + fileName + " line:%3 -- %4::%5 -- %6";
    content = content.arg(QDateTime::currentDateTime().toString()).arg(QThread::currentThread()->objectName()).arg(line).arg(className).arg(methodName).arg(message);

    qDebug(qPrintable(content));
}

void ConsoleLogCommand::warn(const QString &fileName, int line, const QString &className, const QString &methodName, const QString &message)
{
	if (this->m_eLogType > LoggerService::LVL_WARNING)
		return;

	QString content = QObject::tr("%1 [%2] ") + fileName + " line:%3 -- %4::%5 -- %6";
    content = content.arg(QDateTime::currentDateTime().toString()).arg(QThread::currentThread()->objectName()).arg(line).arg(className).arg(methodName).arg(message);

    qDebug(qPrintable(content));
}

void ConsoleLogCommand::error(const QString &fileName, int line, const QString &className, const QString &methodName, const QString &message)
{
	if (this->m_eLogType > LoggerService::LVL_ERROR)
		return;

	QString content = QObject::tr("%1 [%2] ") + fileName + " line:%3 -- %4::%5 -- %6";
    content = content.arg(QDateTime::currentDateTime().toString()).arg(QThread::currentThread()->objectName()).arg(line).arg(className).arg(methodName).arg(message);

    qDebug(qPrintable(content));
}

void ConsoleLogCommand::fatal(const QString &fileName, int line, const QString &className, const QString &methodName, const QString &message)
{
	if (this->m_eLogType > LoggerService::LVL_FATAL)
		return;

	QString content = QObject::tr("%1 [%2] ") + fileName + " line:%3 -- %4::%5 -- %6";
    content = content.arg(QDateTime::currentDateTime().toString()).arg(QThread::currentThread()->objectName()).arg(line).arg(className).arg(methodName).arg(message);

    qDebug(qPrintable(content));
}

void ConsoleLogCommand::setLogLevel(LoggerService::LogType level)
{
    this->m_eLogType = level;
}

}
}
